home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / bpl70n12.zip / ARISOURC.ZIP / FPPOL.ASM < prev    next >
Assembly Source File  |  1993-03-07  |  6KB  |  121 lines

  1.  
  2. ; *******************************************************
  3. ; *                                                     *
  4. ; *     Turbo Pascal Runtime Library Version 7.0        *
  5. ; *     Real Polynomial Evaluation Routine              *
  6. ; *                                                     *
  7. ; *     Copyright (C) 1989-1993 Norbert Juffa           *
  8. ; *                                                     *
  9. ; *******************************************************
  10.  
  11.              TITLE   FPPOL
  12.  
  13.  
  14. CODE         SEGMENT BYTE PUBLIC
  15.  
  16.              ASSUME  CS:CODE
  17.  
  18. ; Externals
  19.  
  20.              EXTRN   RealAdd:NEAR,RealMul:NEAR,RealMulFNoChk:NEAR
  21.              EXTRN   RealSqrNoChk:NEAR
  22.              EXTRN   RealMulNoChk:NEAR,ShortMul:NEAR
  23.  
  24. ; Publics
  25.  
  26.              PUBLIC  RealPoly
  27.  
  28. ;-------------------------------------------------------------------------------
  29. ; RealPoly is a routine that is used in the computation of all transcendental
  30. ; functions with the exception of the exponentiation routines. It is used to
  31. ; compute a polynomial approximation to the desired function. RealPoly computes
  32. ; either P(x^2)*x^2*x+x or P(x^2)*x^2 by way of Horner's method. A pointer to a
  33. ; table of coefficients for the polynomial is passed to the routine. The first
  34. ; coefficient is assumed to be of a special form, such that all but the sixteen
  35. ; most significant mantissa bits are zero. This makes the use of a special fast
  36. ; multiplication possible.
  37. ;
  38. ; INPUT:     DX:BX:AX  argument
  39. ;            CS:DI     pointer to a table of coefficients
  40. ;            CX        number of coefficients to be used
  41. ;            SI        SI <> 0 -> P(x^2) * x^2, SI = 0 -> P(x^2) * x^2 * x + x
  42. ;
  43. ; OUTPUT:    DX:BX:AX  approximated value of function
  44. ;
  45. ; DESTROYS:  AX,BX,CX,DX,SI,DI,Flags
  46. ;-------------------------------------------------------------------------------
  47.  
  48. RealPoly     PROC    NEAR
  49.              CMP     AL, 5Ch           ; abs(argument) < 2^-36 ?
  50.              JB      $poly_end         ; yes, result = arg. to machine precision
  51.              OR      SI, SI            ; test flag
  52.              PUSHF                     ; save flag setting
  53.              PUSH    DX                ; save
  54.              PUSH    BX                ;  argument
  55.              PUSH    AX                ;   on stack
  56.              PUSH    CX                ; save number of coefficients
  57.              PUSH    DI                ; save pointer to table of coefficients
  58.              CALL    RealSqrNoChk      ; multiply argument (!= 0) by itself
  59.              POP     DI                ; get back pointer to table
  60.              POP     CX                ; get back number of coefficients
  61.              PUSH    BP                ; save TURBO-Pascal base pointer
  62.              MOV     BP, SP            ; new base pointer to access argument
  63.              PUSH    DX                ; put
  64.              PUSH    BX                ;  square of argument
  65.              PUSH    AX                ;   on stack
  66.              PUSH    CX                ; save coefficient counter (CH = 0)
  67.              mov     cl, cs:[di]
  68.              inc     di
  69.              push    di
  70.              mov     di, cs:[di]
  71.              call    shortmul
  72.              pop     di
  73.              pop     cx
  74.              inc     di
  75.              inc     di
  76.              dec     cx
  77.              jz      $taylor_done
  78. ;             MOV     CL, CS:[DI]       ; load exponent of first coefficient
  79. ;             XOR     SI, SI            ; load mantissa middle byte of 1. coeff.
  80. ;             SUB     DI, 3             ; fake 6 coefficient bytes
  81. ;             PUSH    DI                ; save pointer to current coefficient
  82. ;             MOV     DI, CS:[DI+4]     ; load mantissa MSW of first coefficient
  83. ;             JMPS    $start            ; start polynomial approximation
  84. $taylor_loop:PUSH    CX                ; save coefficient counter
  85.              PUSH    DI                ; save pointer to current coefficient
  86.              MOV     CX, CS:[DI]       ; get
  87.              MOV     SI, CS:[DI+2]     ;  coefficient
  88.              MOV     DI, CS:[DI+4]     ;   from table
  89.              CALL    RealAdd           ; add coefficient
  90.              MOV     CX, [BP-6]        ; get
  91.              MOV     SI, [BP-4]        ;  saved
  92.              MOV     DI, [BP-2]        ;   square of argument
  93. $start:      CALL    RealMulfNoChk      ; multiply intermediate result by arg.
  94.              POP     DI                ; get pointer to current coefficient
  95.              POP     CX                ; get coefficient counter
  96.              ADD     DI, 6             ; pointer to next coefficient
  97.              LOOP    $taylor_loop      ; loop until coefficients used up
  98. $taylor_done:MOV     SP, BP            ; remove square of argument from stack
  99.              POP     BP                ; restore TURBO-Pascal base pointer
  100.              POP     CX                ; get back
  101.              POP     SI                ;  original
  102.              POP     DI                ;   argument x
  103.              POPF                      ; get polynomial type flag
  104.              JNZ     $poly_end         ;
  105.              PUSH    DI                ; save
  106.              PUSH    SI                ;  x on
  107.              PUSH    CX                ;   stack
  108.              CALL    RealMulfNoChk      ; compute P(x^2)*x^2*x
  109.              POP     CX                ; get
  110.              POP     SI                ;  x from
  111.              POP     DI                ;   stack
  112.              JMP     RealAdd           ; compute P(x^2)*x^2*x+x, exit v. RealAdd
  113. $poly_end:   RET                       ; done
  114. RealPoly     ENDP
  115.  
  116.              ALIGN   4
  117.  
  118. CODE         ENDS
  119.  
  120.              END
  121.